package com.mitac.mcd.cs.mobiletracking.socketserver.report;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class BusinessUtil
{
	public static Log sLogger = LogFactory.getLog("system");
	public static Log aLogger = LogFactory.getLog("application"); 
	
    
    
	/**
     * 获取传递日期所在周的周一
     * @param date
     */
    public static void getFirstDayOfWeek(Calendar date){
    	int day_of_week = date.get(Calendar.DAY_OF_WEEK);
    	if(day_of_week!=1){
    		day_of_week = day_of_week -2;
    	}else{
    		day_of_week = 6;
    	}
    	date.add(Calendar.DATE, -day_of_week);
    }
    
    /**
     * 获取传递日期所在周的周日
     * @param date
     */
    public static void getLastDayOfWeek(Calendar date){
		int day_of_week = date.get(Calendar.DAY_OF_WEEK);
		if(day_of_week!=1){
			day_of_week = date.get(Calendar.DAY_OF_WEEK) - 2;
			date.add(Calendar.DATE, -day_of_week);
			date.add(Calendar.DATE, 6);
		}
    }
    
    /**
     * 获取传递日期所在月的第一天
     * @param date
     */
    public static Date getFirstDayOfMonth(Date date){
    	Calendar calendar = new GregorianCalendar();
    	calendar.setTime(date);
    	calendar.set(Calendar.DATE,calendar.getActualMinimum(Calendar.DATE));
    	return calendar.getTime();
    }
    
    /**
     * 获取传递日期所在月的最后一天
     * @param date
     */
    public static Date getLastDayOfMonth(Date date){
    	Calendar calendar = new GregorianCalendar();
    	calendar.setTime(date);
    	calendar.set(Calendar.DATE,calendar.getActualMaximum(Calendar.DATE));
    	return calendar.getTime();
    }
    
    
    public static void main(String args[]) throws InterruptedException, InstantiationException, IllegalAccessException{
    	Calendar date = Calendar.getInstance();
    	System.out.println(date.get(Calendar.DAY_OF_MONTH));
    }
}
